<template>
  <div class="login">
    <el-form
      ref="loginRef"
      :model="loginForm"
      :rules="loginRules"
      class="login-form"
    >
      <el-form-item prop="username">
        <el-input
          v-model="loginForm.username"
          type="text"
          size="large"
          auto-complete="off"
          placeholder="账号"
        >
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="loginForm.password"
          type="password"
          size="large"
          auto-complete="off"
          placeholder="密码"
          @keyup.enter="handleLogin"
        >
        </el-input>
      </el-form-item>
      <el-form-item style="width: 100%">
        <el-button
          :loading="loading"
          size="large"
          type="primary"
          style="width: 100%"
          @click.prevent="handleLogin"
        >
          <span v-if="!loading">登 录</span>
          <span v-else>登 录 中...</span>
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router";
import { ref } from "vue";

const router = useRouter();
const loginForm = ref({
  username: "",
  password: "",
});

const loginRules = {
  username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
  password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
};

const loading = ref(false);

function handleLogin() {
  if (
    loginForm.value.username == "admin" &&
    loginForm.value.password == "admin@Q123"
  ) {
    loading.value = true
    router.push("/map");
  } else {
    alert("用户名或密码错误");
  }
}
</script>

<style lang="scss" scoped>
.login {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background-image: url("../assets/images/login-background.jpg");
  background-size: cover;
}
.title {
  margin: 0 auto 30px;
  color: #707070;
  text-align: center;
}
.login-form {
  width: 400px;
  padding: 25px 25px 5px;
  background: #ffffff;
  border-radius: 6px;
  .el-input {
    height: 40px;
    input {
      height: 40px;
    }
  }
  .input-icon {
    width: 14px;
    height: 39px;
    margin-left: 0;
  }
}
.login-tip {
  font-size: 13px;
  color: #bfbfbf;
  text-align: center;
}
.login-code {
  float: right;
  width: 33%;
  height: 40px;
  img {
    vertical-align: middle;
    cursor: pointer;
  }
}
.el-login-footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 40px;
  font-family: Arial;
  font-size: 12px;
  line-height: 40px;
  color: #ffffff;
  text-align: center;
  letter-spacing: 1px;
}
.login-code-img {
  height: 40px;
  padding-left: 12px;
}
</style>
